<template>
	<view>
		<simple-toolbar :title="$t('pool.dealRecordPool.dealRecordPool')">
			<view slot="content" class="mg-l-sm h-box">
				<el-radio v-model="radio" label="1">{{ $t('pool.dealRecordPool.in') }}</el-radio>
				<el-radio v-model="radio" label="2">{{ $t('pool.dealRecordPool.out') }}</el-radio>
			</view>
			<view class="update">
				<view class="button" @click="editRecordPool(1)">
					<image src="../../../static/create.png"></image>
					<text>{{ $t('pool.dealRecordPool.newDealRecordPool') }}</text>
				</view>
			</view>
		</simple-toolbar>

		<view class="pad-base table">
			<nav-tab @change-current-tab="dealRecordPool" @ready="dealRecordPool" />
			
			<el-table :data="listData" style="width: 100%">
				<el-table-column align="center" prop="sender" :label="$t('pool.dealRecordPool.sender_wallet')"></el-table-column>
				<el-table-column align="center" prop="recipient" :label="$t('pool.dealRecordPool.recipient_wallet')"></el-table-column>
				<el-table-column align='center' prop="coin" :label="$t('wallet.wallet.coin')"></el-table-column>
				<el-table-column align="center" prop="amount" :label="$t('pool.dealRecordPool.amount')"></el-table-column>
				<el-table-column align="center" :label="$t('pool.dealRecordPool.type')">
					<template slot-scope="scope">
						<text>{{ scope.row.is_deposit ? $t('pool.dealRecordPool.in') : $t('pool.dealRecordPool.out') }}</text>
					</template>
				</el-table-column>
				<el-table-column align="center" prop="record_time" :label="$t('pool.dealRecordPool.record_time')"></el-table-column>
			</el-table>
		</view>
	</view>
</template>

<script>
	import {
		dealRecordPool
	} from "../../../js_sdk/uni-admin/assetPool.js"

	export default {
		data() {
			return {
				cacheCurrentTab: {
					coin: 1
				},
				radio: '1',
				listData: []
			}
		},
		watch: {
			radio() {
				this.dealRecordPool()
			}
		},
		methods: {
			editRecordPool(state, row) {
				if (state == 2) {
					return
				}
				uni.navigateTo({
					url: `./editRecordPool?state=${state}&data=${encodeURIComponent(JSON.stringify(row))}`
				})
			},
			async dealRecordPool(data) {
				this.data = data
				let query = {}
				if (data) {
					query = data
					this.cacheCurrentTab = data
				} else {
					query = this.cacheCurrentTab
				}
				query.is_deposit = this.radio == '1' ? 'True' : 'False'
				let res = await dealRecordPool('get', query)
				this.listData = res.data
				this.listData.forEach(item => {
					item.amount = this.$utils.retain12(item.amount)
					item.record_time = this.$utils.formatDate(item.record_time)
				})
			}
		},
		onShow() {
			// this.dealRecordPool(this.data)
		}
	}
</script>

<style>

</style>
